package com.core.tool.generate;

import java.util.*;
import java.io.File;
import java.lang.reflect.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.core.util.FileUtil;

public class ServiceGenerate {
	private static Log log = LogFactory.getLog(ServiceGenerate.class);

	private TemplateTool templateTool;
	private String objectTag;
	private String clazzTag;
	private String fieldTag;
	private String packTag;

	private String serviceFolder;
	private String extension;
	private String template;

	public void generateService(String logicPack, String clazz,
			String objectname, List<FieldProperty> fieldProperties,
			String folder) {
		try {
			if (fieldProperties == null) {
				fieldProperties = new ArrayList<FieldProperty>();
			}

			Map<String, Object> map = new HashMap<String, Object>();

			map.put(clazzTag, clazz);
			map.put(objectTag, objectname);
			map.put(fieldTag, fieldProperties);
			map.put(packTag, logicPack);

			FileUtil.createDirectory(folder + serviceFolder);

			String url = folder + serviceFolder + clazz + "Service" + extension;

			templateTool.createStaticFile(template, map, url);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getObjectTag() {
		return objectTag;
	}

	public void setObjectTag(String objectTag) {
		this.objectTag = objectTag;
	}

	public String getClazzTag() {
		return clazzTag;
	}

	public void setClazzTag(String clazzTag) {
		this.clazzTag = clazzTag;
	}

	public String getFieldTag() {
		return fieldTag;
	}

	public void setFieldTag(String fieldTag) {
		this.fieldTag = fieldTag;
	}

	public String getPackTag() {
		return packTag;
	}

	public void setPackTag(String packTag) {
		this.packTag = packTag;
	}

	public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}

	public String getTemplate() {
		return template;
	}

	public void setTemplate(String template) {
		this.template = template;
	}

	public String getServiceFolder() {
		return serviceFolder;
	}

	public void setServiceFolder(String serviceFolder) {
		this.serviceFolder = serviceFolder;
	}

	public TemplateTool getTemplateTool() {
		return templateTool;
	}

	public void setTemplateTool(TemplateTool templateTool) {
		this.templateTool = templateTool;
	}

}
